package com.netease.qa.web.utils;

import lombok.Getter;

/**
 * @author zoudongdong
 * @date 2018/2/15
 */
@Getter
public class ServiceResult<T> {

    private int code;//返回码,非200则出错
    private String msg;//提示信息(大部分是报错信息,也可以是提示信息)
    private T data;//返回数据

    private ServiceResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ServiceResult<T> success() {
        return new ServiceResult(Const.SUCCESS, "", null);
    }

    public static <T> ServiceResult<T> success(T data) {
        return new ServiceResult(Const.SUCCESS, "", data);
    }

    public static <T> ServiceResult<T> successMsg(String msg) {
        return new ServiceResult(Const.SUCCESS, msg, null);
    }

    public static <T> ServiceResult<T> success(T data, String msg) {
        return new ServiceResult(Const.SUCCESS, msg, data);
    }

    public static <T> ServiceResult<T> fail(String msg) {
        return new ServiceResult(Const.INTERNAL_ERROR, msg, null);
    }

}
